package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.RolePermissionMapper;
import com.example.servicea.entity.RolePermissionEntity;
import com.example.servicea.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @Author generator.
 * @Date: 2017/10/26 10:58
 */
@Service("rolePermissionServiceImpl")
public class RolePermissionServiceImpl implements RolePermissionService {
	@Autowired
	private RolePermissionMapper rolePermissionMapper;

    @Override
    public boolean insert(RolePermissionEntity obj){
        return SqlHelper.retBool(rolePermissionMapper.insert(obj));
    }
    @Override
    public List<RolePermissionEntity> selectList(RolePermissionEntity rolePermission){
        EntityWrapper<RolePermissionEntity> query = new EntityWrapper<RolePermissionEntity>();
		return rolePermissionMapper.selectList(query);
	}

    @Override
    public Page selectPage(RolePermissionEntity rolePermission, String page, String limit){
        EntityWrapper<RolePermissionEntity> query = new EntityWrapper<RolePermissionEntity>();
        List<RolePermissionEntity> list = rolePermissionMapper.selectPage(
                new Page<RolePermissionEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = rolePermissionMapper.selectCount(query);
        Page RolePermissionEntityPage = new Page();
        return RolePermissionEntityPage;
	}
    @Override
    public int selectCount(RolePermissionEntity rolePermission){
        EntityWrapper<RolePermissionEntity> query = new EntityWrapper<RolePermissionEntity>();
        return rolePermissionMapper.selectCount(query);
	}

    @Override
    public RolePermissionEntity selectOne(RolePermissionEntity rolePermission){
        return rolePermissionMapper.selectOne(new RolePermissionEntity());
	}

    @Override
    public RolePermissionEntity selectById(String id){
        return rolePermissionMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(RolePermissionEntity rolePermission){
        return SqlHelper.retBool(rolePermissionMapper.updateById(rolePermission));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(rolePermissionMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(rolePermissionMapper.deleteBatchIds(list));
	}
	
}
